<template>
  <div id="app">
    <!-- 卡片组件 -->
    <el-card class="login-card">
      <!-- 登录表单 -->
      <!-- 表单容器 -->
      <el-form ref="formRef" :rules="rules" :moble="form" style="margin-top: 50px">
        <!-- 表单项 -->
        <el-form-item prop="mobile">
          <!-- 表单组件 -->
          <el-input v-model="form.mobile" placeholder="请输入手机号"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="form.password" placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="width: 100%" @click="onSubmit">登录</el-button>
        </el-form-item>

      </el-form>
    </el-card>
  </div>
</template>

<script>

export default {
  name: 'LearnFrom',
  components: {

  },
  data() {
    function validateMobile(rule, value, callback) {
      if (value.charAt(2) === '9') {
        callback()
      } else {
        callback(new Error('手机号第三位必须是9'))
      }
    }
    return {
      form: {
        mobile: '',
        password: ''
      },
      rules: {
        mobile: [
          { required: true, message: '手机号不能为空', trigger: 'blur' },
          { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' },
          { validator: validateMobile, trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' },
          { min: 6, max: 16, message: '密码应为6-16位的长度', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    onSubmit() {
      this.$refs.formRef.validate((isok) => {
        console.log(isok)
      })
    }
  }
}
</script>

  <style>
    body {
      padding: 0;
      margin: 0;
    }

    #app {
      width: 100%;
      height: 100vh;
      background-color: pink;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .login-card {
      width: 440px;
      height: 300px;
    }
  </style>
